package com.koi.system.controller.file;

import com.koi.common.utils.file.UploadUtil;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.Map;

/**
 * @author ･ᴗ･
 * @description [FileController]
 */
@Slf4j
@RequestMapping("/koi")
@RequiredArgsConstructor
@RestController
public class FileController {

    @Value("${koi.filePath}")
    private String basePath;

    /**
     * @param fileSize 文件大小
     * @param folderName 上传指定文件夹名称
     * @description [上传单文件-需在WebConfig配置静态资源]
     * @author ･ᴗ･
     */
    @PostMapping("/file/uploadFile/{fileSize}/{folderName}")
    public Map<String, Object> uploadSingleFile(@RequestParam("file") MultipartFile file, @PathVariable("fileSize") Integer fileSize, @PathVariable("folderName") String folderName) {
        Map<String, Object> fileMap = UploadUtil.koiSingleFile(file, basePath + "/" + folderName + "/", fileSize);
        return fileMap;
    }

}
